package com.atguigu.bigdata.scala.mytest.chapter07

object Test_WordCount4 {
  def main(args: Array[String]): Unit = {
    //不同省份的商品点击排行
    val list = List(
      ("zhangsan", "河北", "鞋"),
      ("lisi", "河北", "衣服"),
      ("wangwu", "河北", "鞋"),
      ("zhangsan", "河南", "鞋"),
      ("lisi", "河南", "衣服"),
      ("wangwu", "河南", "鞋"),
      ("zhangsan", "河南", "鞋"),
      ("lisi", "河北", "衣服"),
      ("wangwu", "河北", "鞋"),
      ("zhangsan", "河北", "鞋"),
      ("lisi", "河北", "衣服"),
      ("wangwu", "河北", "帽子"),
      ("zhangsan", "河南", "鞋"),
      ("lisi", "河南", "衣服"),
      ("wangwu", "河南", "帽子"),
      ("zhangsan", "河南", "鞋"),
      ("lisi", "河北", "衣服"),
      ("wangwu", "河北", "帽子"),
      ("lisi", "河北", "衣服"),
      ("wangwu", "河北", "电脑"),
      ("zhangsan", "河南", "鞋"),
      ("lisi", "河南", "衣服"),
      ("wangwu", "河南", "电脑"),
      ("zhangsan", "河南", "电脑"),
      ("lisi", "河北", "衣服"),
      ("wangwu", "河北", "帽子")
    )

    val tuples: List[(String, String, Int)] = list.map(w => (w._2,w._3,1))
    println(tuples)

    val tupleToTuples: Map[(String, String), List[(String, String, Int)]] = tuples.groupBy(w => (w._1,w._2))
    println(tupleToTuples)

    val tupleToInt: Map[(String, String), Int] = tupleToTuples.map(w => (w._1,w._2.size))
    println(tupleToInt)

    val list1: List[(String, String, Int)] = tupleToInt.map(w => (w._1._1,w._1._2,w._2)).toList
    println(list1)

    val stringToTuples: Map[String, List[(String, String, Int)]] = list1.groupBy(w => w._1)
    println(stringToTuples)

//    val stringToTuples1: Map[String, List[(String, String, Int)]] = stringToTuples.map(w => (w._1,w._2.sortBy(s => s._3)(Ordering.Int.reverse)))
//    println(stringToTuples1)

    val stringToTuples1: Map[String, List[(String, String, Int)]] = stringToTuples.mapValues(w => w.sortBy(s => s._3)(Ordering.Int.reverse))
    println(stringToTuples1)
  }
}
